<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class AjaxController extends Controller
{
	//验证注册
    public function getUser(Request $request){
        $h_uname=$request->input('h_uname');
        $res=DB::table('home_user')->where('h_uname','=',$h_uname)->first();
        if($res>0){
            return  0;
        }else{
            return 1;
        }
    }

    //抽奖操作
    public function getChoujiang(Request $request){
    	$data=$request->all();
    	$old=DB::table('home_user')->where('h_uid',$data['h_uid'])->first();
    	$jiangpin=$old['jiangpin']+$data['info'];
    	$jifen=$old['h_ujifen']-10000;
    	$info=DB::table('home_user')->where('h_uid',$data['h_uid'])->update(['clickTime'=>date('Y-m-d H:i:s',time()),'jiangpin'=>$jiangpin,'h_ujifen'=>$jifen,'every'=>$data['info']]);
    	if($old['h_ujifen']<10000){
    		return '积分不足,购买商品即可获得大量积分哟!';
    	}else{
    		return $old;
    	}

    	
    }
}
